package com.qfjy.controller;

import com.qfjy.client.VideoInfoControllerFeignClient;
import com.qfjy.entity.po.MeetingPub;
import com.qfjy.service.MeetingPubService;
import com.qfjy.util.result.ResultCode;
import com.qfjy.util.result.ResultJson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

/**
 * @ClassName MeetingPubController
 * @Description TODO
 * @Author guoweixin
 * @Date 2022/4/24
 * @Version 1.0
 */
@Controller
@RequestMapping("meetingPub")
@Slf4j
public class MeetingPubController {

    @Autowired
    private MeetingPubService meetingPubService;

    @Autowired
    private RestTemplate restTemplate;

    /**视频微服务  VideoInfo控制器类*/
    @Autowired
    private VideoInfoControllerFeignClient videoInfoControllerFeignClient;

    @ResponseBody
    @GetMapping("/get")
    public ResultJson selectMeetingPubByPcode(@RequestParam("pcode")String pcode){


       MeetingPub meetingPub= meetingPubService.selectMeetingPubByPcode(pcode);

       log.info("查询的是会议微服务--》{}",meetingPub);


        if(meetingPub==null){
            return  new ResultJson(null, ResultCode.NOT_DATA);
        }

      String videoResult=videoInfoControllerFeignClient.selectVideoInfoByPcode(meetingPub.getPcode());
        meetingPub.setRemark(videoResult);


      String resultInsert=videoInfoControllerFeignClient.insertVideoInfo("测试添加数据");

      meetingPub.setPtitle(resultInsert);

        return new ResultJson(meetingPub,ResultCode.SUCCESS);
    }



    //服务间的通信调用  调用 视频微服务接口
    /**
     * param1 url 请求的地址
     * param2  responsType 响应类型（JAVA泛型）
     * param3 参数数据列表
     */
    //  RestTemplate: String url="http://localhost:8085/videoInfo/get?pcode="+meetingPub.getPcode();
    // Ribbon+RestTemplate:
//    String url="http://SANFI-VIDEO/videoInfo/get?pcode="+meetingPub.getPcode();
//    String videoResult= restTemplate.getForObject(url,String.class);
//
//        meetingPub.setRemark(videoResult);

}
